<?php

namespace common\models;

use Yii;

/**
 * This is the model class for table "per_category".
 *
 * @property string $id
 * @property string $per_name
 * @property integer $status
 */
class PerCategory extends \yii\db\ActiveRecord
{

    /**
     * @inheritdoc
     */
    public static function tableName()
    {
        return 'per_category';
    }

    /**
     * @inheritdoc
     */
    public function rules()
    {
        return [

            //[['per_name'], 'required'],
            [['per_name'],'safe'],
            [['status'], 'integer'],
            [['status'],'default','value'=>0],  //默认状态为0，【0为显示，1为不显示】
            [['per_name'], 'string', 'max' => 10],
        ];
    }

    /**
     * @inheritdoc
     */
    public function attributeLabels()
    {
        return [
            'id' => '主键',
            'per_name' => '分类名称',
            'status' => '分类状态',
        ];
    }


    public function getArticles()
    {
        return $this->hasMany(Article::className(), ['id' => 'article_id'])->viaTable('article_and_category', ['category_id' => 'id'])->inverseOf('categories');
    }

}
